﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Chemical.BLL;
using Yipusoft.Chemical.Model;

public partial class BasicBase_Chemical_ChemicalQurey : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }
    }

    void init()
    {
        #region 权限
        bool isPermission = false;
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201600"))
        {
            isPermission = true;
        }
        else
        {

            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201602"))
            {
                isPermission = true;
            }

        }
        if (!isPermission)
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
            return;
        }
        #endregion
        List<string> list = Chemical.GetAllChemicalClass();
        ChemicalClass.Items.Add("");
        foreach (string item in list)
        {
            ChemicalClass.Items.Add(item);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //类型
        string strWhere = "";

        if (ChemicalClass.SelectedValue != "")
        {
            strWhere = " ChemicalClass like '%" + ChemicalClass.SelectedValue + "%'";
        }
        //中文名
        if (CnName.Text.Trim() != "")
        {
            if (strWhere != "")
            {
                strWhere += " and ";
            }

            strWhere += " CnName like '%" + CnName.Text + "%'";
        }


        //英文名
        if (EnName.Text.Trim() != "")
        {
            if (strWhere != "")
            {
                strWhere += " and ";
            }

            strWhere += " EnName like '%" + EnName.Text + "%'";
        }
        //其它
        strWhere += GetString(OtName, "OtName", strWhere);

        //参照处置方案
        strWhere += GetString(ReferenceScheme, "ReferenceScheme", strWhere);
        //参照化学品
        strWhere += GetString(ReferenceChemical, "ReferenceChemical", strWhere);


        //LD50
        strWhere += GetString(LD50, "LD50", strWhere);
        //LC50
        strWhere += GetString(LC50, "LC50", strWhere);

        strWhere += GetString(Smell, "Smell", strWhere);
        strWhere += GetString(Color, "Color", strWhere);

        strWhere += GetString(Status, "Status", strWhere);
        strWhere += GetString(Danger, "Danger", strWhere);

        strWhere += GetString(Resolvent, "Resolvent", strWhere);
        strWhere += GetString(Package, "Package", strWhere);

        strWhere += GetString(Avoid, "Avoid", strWhere);
        strWhere += GetString(Skin, "Skin", strWhere);

        strWhere += GetString(Eye, "Eye", strWhere);
        strWhere += GetString(RespiratoryTract, "RespiratoryTract", strWhere);

        strWhere += GetString(Stifle, "Stifle", strWhere);
        strWhere += GetString(Nervous, "Nervous", strWhere);


        strWhere += GetString(RespiratorySystem, "RespiratorySystem", strWhere);
        strWhere += GetString(DigestiveSystem, "DigestiveSystem", strWhere);

        strWhere += GetString(CirculatorySystem, "CirculatorySystem", strWhere);
        Response.Redirect("ChemicalList.aspx?where=" + strWhere);

    }

    string GetString(TextBox txt, string Name, string strWhere)
    {
        string cc = "";
        if (txt.Text.Trim() != "")
        {
            if (strWhere != "")
            {
                strWhere += " and ";
            }

            cc += " " + Name + " like '%" + txt.Text + "%'";
        }
        return cc;
    }
    string GetString(DropDownList txt, string Name, string strWhere)
    {
        string cc = "";
        if (txt.SelectedValue != "")
        {
            if (strWhere != "")
            {
                strWhere += " and ";
            }

            cc += " " + Name + " like '%" + txt.SelectedValue + "%'";
        }
        return cc;
    }
}
